﻿#include"Seqlist.h"
#include "图1.h"

//初始化
void Inite(AdjMGraph* G, int n)
{
	int i, j;
	for (i = 0; i < n; i++)
	{
		for  (j = 0; j < n; j++)
		{
			if (i == j)
			{
				G->edge[i][j] = 0;
			}
			else
			{
				G->edge[i][j] = 114514;
			}
		}
	}
	G->Numofedges = 0;
	SLInit(&G->Vertices);
}

//插入顶点
void InsertV(AdjMGraph* G, SLdatatpye vertex)
{
	SLPushBack(&G->Vertices, vertex);
}

//插入边
void InsertE(AdjMGraph* G, int v1, int v2, int weight)
{
	if (v1 < 0 || v1 >= G->Vertices.size || v2 < 0 || v2 >= G->Vertices.size)
	{
		printf("参数v1、v2出错!\n");
		return;
	}

	G->edge[v1][v2] = weight;
	G->Numofedges++;
}

//删除边
void DeleteE(AdjMGraph* G, int v1, int v2)
{
	if (v1 < 0 || v1 > G->Vertices.size || v2 < 0 || v2 > G->Vertices.size || v1 == v2)
	{
		printf("参数v1或v2出错!\n");
		return;
	}
	if (G->edge[v1][v2] == 114514 || v1 == v2)
	{
		printf("该边不存在!\n");
		return;
	}	
	G->edge[v1][v2] = 114514;
	G->Numofedges--;
}

//取下一个邻接顶点
int GetNextV(AdjMGraph G, int v1, int v2)
{
	int col;
	if (v1 < 0 || v1 > G.Vertices.size || v2 < 0 || v2>G.Vertices.size)
	{
		printf("参数v1或v2越界出错!\n");
		return -1;
	}
	for (col = v2 + 1; col < G.Vertices.size; col++)
	{
		if (G.edge[v1][col] > 0 && G.edge[v1][col] < 114514)return col;
	}
	return -1;
}

//取第一个邻接顶点
int GetFirstV(AdjMGraph G, int v)
{
	int col;
	if (v < 0 || v >= G.Vertices.size)
	{
		printf("参数v1越界出错");
		return -1;
	}
	for (col = v; col < G.Vertices.size; col++)
	{
		if (G.edge[v][col] > 0 && G.edge[v][col] < 114514)
			return col;
	}
	return -1;
}